<?php

class Login extends CI_Controller {
	
	
	public function index(){
		$this->load->model('Patient','p');
		$this->load->model('Nutritionist','n');
		$data['title'] = 'NutriApp';
		
		if(($this->p->is_logged())||($this->n->is_logged())){
			 redirect('/', 'refresh');
		}else{
			$this->load->view('index_login', $data);
		}
	}
	

	public function in(){
		$this->load->model('Patient','p');
		$id_patient = $this->p->validate();
		
		if ($id_patient){		
			$this->p->login($id_patient);
			redirect('/', 'refresh');
		}else{
			$this->load->model('Nutritionist','n');
			$id_nutritionist = $this->n->validate();
			if ($id_nutritionist){		
				$this->n->login($id_nutritionist);
				redirect('/', 'refresh');
			}
		}
		redirect('/login', 'refresh');
		
	}
	
	public function out(){
		$this->load->model('Patient','p');
		if($this->p->is_logged()){
			$this->p->logout();
		}else{
			$this->load->model('Nutritionist','n');
			$this->n->logout();
		}
	}
	
	public function changePswd(){
		$this->load->model('Patient','p');
		$this->p->changePswd();
	}
	
}
?>
